<script>
	function check()
	{
		if($("comment_comment").value.replace(/(^\s*)|(\s*$)/g,"")=="")
		{
			alert("回复不能为空！")
			return false;
		}else
		{
			return true;
		}
	}
</script>
<div>
<div class="blog_tite"><%="Comments"%></div>
<%if session[:user]%>
    <%# form_remote_for :comment, :url => { :controller => "comment", :action => "comment", :id => asset.id }, :html=>{:multipart=>true},:before=>'return check()' do |form| %>
    <form action="/comment/comment/<%=asset.id%>" enctype="multipart/form-data" method="post" onsubmit="if(check()){new Ajax.Request('/comment/comment/<%=asset.id%>', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;}else{return false}">
           <div class="blog_w"><%#= form.text_area :comment, :rows=>10 , :cols=>50, :class => "blog_input" %>
           <textarea class="blog_input" cols="50" id="comment_comment" name="comment[comment]" rows="5"></textarea>
           </div>
             <%#= form.hidden_field :commentable_type, :value=>commentable_type%> 
           <input id="comment_commentable_type" name="comment[commentable_type]" type="hidden" value="<%=commentable_type%>" /> 
           <div class="tetx_right blogpd"><label><%= submit_tag " Create " , :class => "button" %></label></div>
	<%# end %>
     </form>
  <%else%>
	<div class="basefontsize">
	<%="Please login first"%>:
	<% form_tag '/account/login' do -%>
	<p><label for="login"><%="Login"%></label><br/>
	<%= text_field_tag 'login' %></p>
	<p><label for="password"><%="Password"%></label><br/>
	<%= password_field_tag 'password' %></p>
	<!-- Uncomment this if you want this functionality
	<p><label for="remember_me">Remember me:</label>
	<%= check_box_tag 'remember_me' %></p>
	-->
	<p><%= submit_tag "Log in" %> <%=link_to "Sign up", :controller => "account", :action => "signup" %></p>
	<% end -%>
	</div>
<%end%>
</div>


<%counter = asset.comments.size
asset.comments.each do |comment|%>
          <div style="background-color:<%=counter.divmod(2)[1] == 0 ? '#ddd' : '#F0F0F0'%>;width:540px">
		<div class="l">
                     <%=comment.user.nickname%> 
                     <%if session[:user]==comment.user.id%>
                     <%=link_to "<img src='/images/icon_delete.png'>",{:controller=>"comment",:action=>"destroy",:id=>comment.id},:onclick=>"return confirm('确定删除留言吗？')"%>
                     <%end%>
		</div>
		<div class="r w_472">
			<div>
			</div>
			<div id="guestbook_tit"><br><%=comment.comment%><br><br></div>
                        <div><%=fmt_time(comment.created_at,"")%></div>
		</div>
		<div class="c"></div>
	</div>
<%counter = counter - 1
end%>



